<?php
class CommentsController extends AppController {
	
	public function add($postID = null){

		// if method is 'post', begin add comment
		if ($this->request->is('post')) {
			$this->Comment->create();
			$temp = array('user' => $this->request->data['user'],
					 'content' => $this->request->data['content'],
					'post_ID' => $postID);
			 if ($this->Comment->save($temp)) {
				$this->Session->setFlash('Comments Save', 'default', array('class' => 'alert alert-success'));
				
				//set redirect to view post detail
				return $this->redirect(array('controller' => 'posts', 'action' => 'view/'.$postID));
			}
			
			//error when comment cannot be save
			$this->Session->setFlash('unable to save comment', 'default', array('class' => 'alert alert-danger')); 
		}
	}
}